<?php
class Backend_Import_Controller extends Backend_Controller{
    
    /**
     * (non-PHPdoc)
     * @see Backend_Controller::indexAction()
     */
     public function indexAction(){    
        $res = Resource::getInstance();    
	    $res->addJs('/js/app/system/ImportPanel.js'  , 1);
	    $res->addJs('/js/app/system/crud/import.js'  , 1);
	    $res->addCss('/js/lib/ext_ux/css/fileuploadfield.css');
	    $res->addJs('/js/lib/ext_ux/FileUploadField.js'  , 1);

	     $this->_resource->addInlineJs('
            var canPublish =  '.((integer)$this->_user->canPublish($this->_module)).';
        	var canEdit = '.((integer)$this->_user->canEdit($this->_module)).';
        	var canDelete = '.((integer)$this->_user->canDelete($this->_module)).';
        ');
    }
    
    
    public function uploadAction(){
    	sleep(1);
		
		//echo json_encode(array('success'=>false,'msg'=>'Cannot upload file')); exit;
		// ключи столбиков должны начинаться с col и считаться с 0
		// отправляется набор нескольких первых строк ?
		$data = array();
		for($i=0;$i<30;$i++){
			
			$data[] = array(
				'col0'=>'Vendor'.rand(0,6),
				'col1'=>rand(1000,9999),
				'col2'=>rand(1,700),
				'col3'=>rand(1,700),
				'col4'=>rand(1,700),
				'col5'=>rand(1,700),
				'col6'=>rand(1,700),
			);
		}
		
		echo json_encode(array(
			'success'=>true,
			'data'=>$data,
			'col_count'=>sizeof($data[0])
		)); exit();
    	
    }
    
    public function importAction(){
    	echo json_encode(array('success'=>true));
		exit();
    }
}